// $Id: basic.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#include <boost/test/unit_test.hpp>
#include <xpcom/uuid.hpp>

BOOST_AUTO_TEST_CASE(test_basic)
{
    using namespace xpcom;

    uuid id1 = { 0xf489ad32, 0x769a, 0x4664,
            { 0xa7, 0xd4, 0x42, 0xbe, 0x1e, 0x19, 0xea, 0x66 } };
    uuid id2 = { 0xf489ad32, 0x769a, 0x4664,
            { 0xa7, 0xd4, 0x42, 0xbe, 0x1e, 0x19, 0xea, 0x66 } };
    uuid id3 = { 0 };
    uuid id4 = { 0 };

    uuid id11 = { 0xf489ad33, 0x769a, 0x4664,
            { 0xa7, 0xd4, 0x42, 0xbe, 0x1e, 0x19, 0xea, 0x66 } };
    uuid id12 = { 0xf489ad32, 0x769b, 0x4664,
            { 0xa7, 0xd4, 0x42, 0xbe, 0x1e, 0x19, 0xea, 0x66 } };
    uuid id13 = { 0xf489ad32, 0x769a, 0x4665,
            { 0xa7, 0xd4, 0x42, 0xbe, 0x1e, 0x19, 0xea, 0x66 } };
    uuid id14 = { 0xf489ad32, 0x769a, 0x4664,
            { 0xa7, 0xd4, 0x42, 0xbe, 0x1e, 0x20, 0xea, 0x66 } };

    BOOST_CHECK(id1 == id1);
    BOOST_CHECK(id1 == id2);
    BOOST_CHECK(!(id1 == id3));
    BOOST_CHECK(id1 != id3);
    BOOST_CHECK(id1.compare(id2) == 0);
    BOOST_CHECK(id1.compare(id3) > 0);

    BOOST_CHECK(id2 == id1);
    BOOST_CHECK(id2 == id2);
    BOOST_CHECK(!(id2 == id3));
    BOOST_CHECK(id2 != id3);
    BOOST_CHECK(id2.compare(id1) == 0);
    BOOST_CHECK(id2.compare(id3) > 0);

    BOOST_CHECK(!(id3 == id1));
    BOOST_CHECK(id3 != id2);
    BOOST_CHECK(id3 == id3);
    BOOST_CHECK(id3 == id4);
    BOOST_CHECK(!(id3 != id3));
    BOOST_CHECK(id3.compare(id4) == 0);
    BOOST_CHECK(id3.compare(id1) < 0);

    BOOST_CHECK(id3 < id1);
    BOOST_CHECK(id1 > id3);
    BOOST_CHECK(id3 >= id4);
    BOOST_CHECK(id3 <= id4);
    BOOST_CHECK(id1 >= id3);
    BOOST_CHECK(id3 <= id1);

    BOOST_CHECK(id1.compare(id11) < 0);
    BOOST_CHECK(id1.compare(id12) < 0);
    BOOST_CHECK(id1.compare(id13) < 0);
    BOOST_CHECK(id1.compare(id14) < 0);
    BOOST_CHECK(id11.compare(id1) > 0);
    BOOST_CHECK(id12.compare(id1) > 0);
    BOOST_CHECK(id13.compare(id1) > 0);
    BOOST_CHECK(id14.compare(id1) > 0);

    id2 = id3;
    BOOST_CHECK(id1 != id2);
    BOOST_CHECK(id3 == id2);
    id2 = id1;

    id1.swap(id3);
    BOOST_CHECK(id2 == id3);
    BOOST_CHECK(id1 == id4);

    swap(id3, id1);
    BOOST_CHECK(id1 == id2);
    BOOST_CHECK(id3 == id4);

    BOOST_CHECK(!id1.is_nil());
    BOOST_CHECK(!id2.is_nil());
    BOOST_CHECK(id3.is_nil());
    BOOST_CHECK(id4.is_nil());

    id1 = uuid::nil;
    id3 = uuid::nil;
    BOOST_CHECK(id1.is_nil());
    BOOST_CHECK(!id2.is_nil());
    BOOST_CHECK(id3.is_nil());
    BOOST_CHECK(id4.is_nil());
}
